package com.example.task;

import com.example.mapper.ShoppingCartDao;
import com.example.mapper.StoreShoppingCartDao;
import com.example.utils.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * 1. @ClassDescription:
 * 2. @author: Z
 * 3. @date: 2024年04月19日 14:38
 */
@Slf4j
@Component
public class ShoppingCartTask {

    @Autowired
    private StoreShoppingCartDao storeShoppingCartDao;

    @Autowired
    private ShoppingCartDao shoppingCartDao;



    /**
     * @description: 每天清除购物车
     * @time: 2024年4月15日17:14:57
     */
    @Scheduled(cron = "0 0 1 * * ?") //每天凌晨一点触发
    public void processDeliveryStoreShoppingCart(){
        log.info("清空购物车：{}", LocalDateTime.now());

//        LocalDateTime time = LocalDateTime.now().plusMinutes(-60);
        storeShoppingCartDao.deleteByStoreId(null);
        shoppingCartDao.deleteById(null);
    }

}
